<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class Keuangan extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->helper('flexigrid');
        $this->load->library('flexigrid');
		$this->load->library('session');
		$this->load->model('keuangan_model');
	}
	
	function cek_login(){
		$id_hak = $this->session->userdata('id_hak');
		
		if($id_hak < 1 || $id_hak > 2 || $id_hak == ''){
			redirect ('login');
		}
		
	}
	
	function index() {
        $colModel['no'] = array('No', 30, TRUE, 'center', 0);
        $colModel['Nama_Batch'] = array('Nama Angkatan atau Batch', 150, TRUE, 'center', 1);
        $colModel['Total_Pembayaran'] = array('Total Pembayaran', 100, TRUE, 'left', 0);
        

        $gridParams = array(
            'width' => 'auto',
            'height' => 300,
            'rp' => 10,
            'rpOptions' => '[5,10,15,20,25,40]',
            'pagestat' => 'Menampilkan: {from} hingga {to} dari {total} data.',
            'blockOpacity' => 0.5,
            'title' => 'Daftar Pembayaran Per Batch ',
            'showTableToggleBtn' => true
        );

        
        $grid_js = build_grid_js('flex1', site_url("keuangan/keuangan/grid_pembayaran_perbatch/"), $colModel, 'Nama_Batch', 'asc', $gridParams);
        
       
        $data_grid['js_grid'] = $grid_js;

        
        //remdering view
        $data['title'] = 'Daftar Pembayaran Per Batch';
        $this->template->write_view('header', 'template/header', $data);
        $this->template->write_view('content', 'keuangan/grid_pembayaran_batch', $data_grid);
        $this->template->write_view('footer', 'template/footer', $data);
        $this->template->render();
    }
        
    function grid_pembayaran_perbatch() {
        $valid_fields = array('Nama_Batch', 'Total_Pembayaran');
        $this->flexigrid->validate_post('Nama_Batch', 'asc', $valid_fields);
        $records = $this->keuangan_model->get_transaksi_perbatch();
        $this->output->set_header($this->config->item('json_header'));

        $no = 0;
        foreach ($records['records']->result() as $row) {
		
			$record_items[] = array(
			$row->ID_BATCH,
			$no = $no + 1,
			$row->NAMA_BATCH,
			'Rp. '. number_format($row->TOTAL_PEMBAYARAN, null, ',', '.'). ',-',
			);
		}
		if (isset($record_items))
            $this->output->set_output($this->flexigrid->json_build($records['record_count'], $record_items));
        else
            $this->output->set_output('{"page":"1","total":"0","rows":[]}');
	}
}
?>